<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'数据库管理', styles:'bootstrap,font-awesome,animate,style,dtvalidate,codemirror'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>

</head>
<body>
<!-- START 内容部分 -->
<div class="container">
    <form class="form-horizontal" id="info-form" method="post">
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">待执行SQL:</label>
            <div class="col-sm-10">
                <textarea id="sqlcode" class="form-control" name="sql" valid="r" validTitle="数据库SQL" validInfoArea="sql_info_area"></textarea>
                <p class="help-block" id="sql_info_area"></p>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="execute-btn btn btn-primary">
                    <i class="fa fa-save"></i> 执行
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,codemirror,codemirror-sql,layer'}){}%>
<script>
    var cvalidator;
    $(function(){
        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));

        var editor = CodeMirror.fromTextArea(document.getElementById("sqlcode"), {
            lineNumbers: true,
            name: 'SQL'
        });

        //提交表单
        $('.execute-btn').on('click',function(){
            editor.save();

            if(!cvalidator.validResult()){
                $.fn.dlshouwen.validator.tools.toast('验证失败！', 'error', 2000);
                return;
            }

            //数据提交
            $.post('${ctxPath}/power/dbmanager/run.do',$('#info-form').serialize(),function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                }
            });
        });
    });
</script>
</body>
</html>